//
//  SHCasherCenterController.m
//  JiFengDaRen
//
//  Created by SH_iOS on 2017/11/3.
//  Copyright © 2017年 SH_iOS. All rights reserved.
//
#import "CustomPayWaysModel.h"//支付方式模型
#import "SHCasherCenterController.h"
#import "YBPopupMenu.h"
#import "SHTradingQuryController.h"
#import "CodeCell.h"
#import "UnionpayCell.h"
#import "SHNoticeView.h"
#import "BaseToolViewController.h"
#import "HomeNoticeModel.h"
#import "SHUserCenterHttp.h"
//#import "PaymentAmountController.h"

#define BASEBLUECOLOR [UIColor colorWithHexString:@"#508cee"]
#define CODECELLID @"codeCellId"
#define UNIONCELLID @"unionpayCellId"

@interface SHCasherCenterController()<UITableViewDelegate,UITableViewDataSource, YBPopupMenuDelegate,SHNoticeViewDelegate>

@property(nonatomic,assign)BOOL isSdUser;//是否是杉德用户
@property(nonatomic,strong)UITableView *tableView;//主列表
@property(nonatomic,strong)SHNoticeView * noticeView;//通知跑马灯
@property(nonatomic,strong)HomeNoticeModel *noticeModel;//通知模型
@property(nonatomic,strong)NSMutableArray *casherPaymentDataArray;//支付方式
@property(nonatomic,assign)NSInteger cashPaymentType;//银联支付类型



@end

@implementation SHCasherCenterController

#pragma mark - 设置状态栏字体颜色
- (UIStatusBarStyle)preferredStatusBarStyle{
    
    return  UIStatusBarStyleLightContent;
}

#pragma mark - 视图将要出现 重启跑马灯动画
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [SHUserCenterHttp  requstUserInfoSuccess:^(UserModel *userModel) {
        
    } complection:^(id result) {
        
    } failure:^(id erro) {
        
    }];
   
}

#pragma mark - 支付方式数组
- (NSMutableArray *)casherPaymentDataArray{
    
    if (!_casherPaymentDataArray) {
        
        _casherPaymentDataArray = [NSMutableArray arrayWithCapacity:10];
    }
    return _casherPaymentDataArray;
}
#pragma mark - 主列表
- (UITableView *)tableView{
    if (!_tableView) {
        
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth,KScreenHeight) style:UITableViewStylePlain];
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedRowHeight = 0;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        //微信支付宝合码为一二维码cell
        [_tableView registerClass:[CodeCell class] forCellReuseIdentifier:CODECELLID];
        //银联支付一cell
        [_tableView registerClass:[UnionpayCell class] forCellReuseIdentifier:UNIONCELLID];
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
    }
    return _tableView;
}



#pragma mark - 查询是否是杉德用户
- (void)checkUserIsSdUser{
    //查询是否杉德用户
    
    [SHHomeModelView checkSdPayMethodByUserSuccess:^(NSInteger status) {
        
        if (status) {
            _isSdUser = YES;
            
            CustomPayWaysModel *sdModel = [[CustomPayWaysModel alloc]init];
            sdModel.name = @"杉德收款";
            sdModel.image = @"sdpay";
            [self.casherPaymentDataArray addObject:sdModel];
            [self.tableView reloadData];
            
        }
    }];
    
}


#pragma mark - 出事收款支付方式数组
- (void)initCasherPaymentDataArray{
    
    
    //微信 支付宝合码为一收款
    CustomPayWaysModel *wxalipayModel = [[CustomPayWaysModel alloc]init];
    wxalipayModel.name = @"微信支付宝合码为一";
    wxalipayModel.image = @"";
    [self.casherPaymentDataArray addObject:wxalipayModel];
    
  
    //我是瀚付
    CustomPayWaysModel *shangfuModel = [[CustomPayWaysModel alloc]init];
    shangfuModel.name = @"我是瀚付";
    shangfuModel.image = @"my_han_pay";
    [self.casherPaymentDataArray addObject:shangfuModel];
    
    

    
    
}
#pragma mark - 加载视图
- (void)viewDidLoad{
    [super viewDidLoad];
    self.title = @"我是瀚付";
   self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:KSHSystemFont(18)};

    self.view.backgroundColor = BASEBLUECOLOR;
    self.navigationController.navigationBar.barTintColor = BASEBLUECOLOR;
    [self.leftBackBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
    [self.navigationLine removeFromSuperview];
    [self configNavUI];
    [self  initCasherPaymentDataArray];//设置收款支付方式
    [self.view addSubview:self.tableView];
    [self.tableView reloadData];
    
    [self checkUserIsSdUser];//查询是否是杉德用户
   
    
   
}


#pragma mark - 初始化导航栏元素
- (void)configNavUI{
    
    UIButton *shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    shareBtn.frame = CGRectMake(0, 0,28, 28);
    [shareBtn addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
    [shareBtn setImage:[UIImage imageNamed:@"expand2"] forState:UIControlStateNormal];
    
    UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithCustomView:shareBtn];
    
    
    UIButton *menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    menuBtn.frame = CGRectMake(0, 0, 28, 28);
    [menuBtn addTarget:self action:@selector(menu:) forControlEvents:UIControlEventTouchUpInside];
    [menuBtn setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal];
    UIBarButtonItem *menuItem = [[UIBarButtonItem alloc] initWithCustomView:menuBtn];
    self.navigationItem.rightBarButtonItems  = @[menuItem,shareItem];
        
}


#pragma mark - tableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.casherPaymentDataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {

        return (KScreenWidth - __I6Width(50) + __I6Height(30));
    }else{
        return __I6Height(65);
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (indexPath.row == 0) {
        CodeCell *codeCell = [tableView dequeueReusableCellWithIdentifier:CODECELLID forIndexPath:indexPath];
        codeCell.backgroundColor = [UIColor clearColor];
        codeCell.contentView.backgroundColor = [UIColor clearColor];
        codeCell.selectionStyle = UITableViewCellSelectionStyleNone;
        return codeCell;
    }else{
        
        UnionpayCell *unionpayCell = [tableView dequeueReusableCellWithIdentifier:UNIONCELLID forIndexPath:indexPath];
        unionpayCell.contentView.backgroundColor = [UIColor clearColor];
        unionpayCell.backgroundColor = [UIColor clearColor];
        unionpayCell.selectionStyle = UITableViewCellSelectionStyleNone;
        CustomPayWaysModel *paywaysModel = self.casherPaymentDataArray[indexPath.row];
        [unionpayCell setLeftImg:paywaysModel.image paymentName:paywaysModel.name];
        if (indexPath.row == 1 ){
            unionpayCell.payNewImgView.image = [UIImage imageNamed:@"cash_pay_new"];
        }
        return unionpayCell;
    }
    
}

//设置组的头视图高度
- (CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section{
    if (_noticeModel.url != nil) {
        
        return __I6Height(36);
    }else{
        return 0;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    return  self.noticeView;

}

#pragma mark - 选择收款方式
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView  deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row == 0) {
        
        return;
    }
//    PaymentAmountController *paymentAmountVc =    [[PaymentAmountController alloc]init];
//    CustomPayWaysModel *payWaysModel = self.casherPaymentDataArray[indexPath.row];
//    paymentAmountVc.title = payWaysModel.name;

    if (indexPath.row == 1) {//银联支付
     
    }else if(indexPath.row == 2){//杉德支付
//
//        paymentAmountVc.cashPaymentType  = SHCashPaymentSdPay ;
//
//        [self.navigationController pushViewController:paymentAmountVc animated:YES];
        
    }

}


#pragma mark - 事件处理
#pragma mark -- 弹出菜单
#define ICONS  @[@"exchange",@"locked"]
- (void)menu:(UIButton *)btn{
    
    UIView *view =    [[UIView alloc]initWithFrame:CGRectMake(KScreenWidth - 40, 15, 40, 40)];
    NSArray *titltArray = _isSdUser ?  @[@"交易记录", @"绑定刷卡器"] : @[@"交易记录"];
    [YBPopupMenu showRelyOnView:view titles:titltArray icons:ICONS menuWidth:__I6Width(140) delegate:self];
    
    
}

#pragma mark -- YBPopupMenuDelegate 菜单选择点击事件
- (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu
{
    
    if (index == 0 ) {//查看交易记录
        
        //
        [self.navigationController pushViewController:[[SHTradingQuryController alloc]init] animated:YES];
        
    }else if(index == 1){//绑定刷卡器
        
        
        
    }else{//分享
        
    
    }
    
}


#pragma mark -- 分享

- (void)shareAction{

}


@end
